<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>删除帖子</title>
<link rel="stylesheet" href="../webjars/layui/2.5.6/css/layui.css"
	media="all">


</head>
<body>
	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 20px;">
		<legend>删除帖子</legend>
	</fieldset>
	<form class="layui-form" action="">
		<div class="layui-form-item">
			<label class="layui-form-label">帖子标题</label>
			<div class="layui-input-block">
				<input v-model="pname" type="text" name="username" lay-verify="required"
					lay-reqtext="帖子标题不能为空！" placeholder="请输入(必填)" autocomplete="off"
					class="layui-input">
			</div>
		</div>
		
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button  type="submit" class="layui-btn" lay-submit=""
					lay-filter="demo1" @click.prevent="remove">删除提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
		<div class="layui-form">
  <table class="layui-table">
    <colgroup>
      <col width="150">
      <col width="150">
      <col width="200">
      <col>
    </colgroup>
    <thead>
      <tr>
        <th>帖子标题</th>
      </tr> 
    </thead>
    <tbody @click="getval(p.pname)" v-for="p in list">
      <tr>
        <td>{{p.pname}}</td>
      </tr>
    </tbody>
  </table>
</div>
		
</form>
		
	
<!-- vue -->
<script type="text/javascript"src="https://lib.baomitu.com/vue/2.6.12/vue.min.js"></script>
<!-- axios -->
<script type="text/javascript"src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.0/axios.min.js"></script>
<script src="../webjars/layui/2.5.6/layui.all.js" charset="utf-8"></script>
<script type="text/javascript">
	var v1 = new Vue({
	 el:".layui-form",
	 data:{
		
		pname:"",
		list :[],
	 },
	 created(){
		 axios.post("../post/searchPost.s").then(res=>{
				this.list = res.data;
			})
	 },
	 methods:{
		 remove(){
			 var params = new URLSearchParams();
			 params.append("pname",this.pname);
			 axios.post("../post/removePost.s",params).then(res=>{
				 alert(res.data.msg);
				 location.reload();
			 })
		 },
		 getval(pname){
			 this.pname = pname;
		 }
	 },
	 mounted(){
		 
		 
		 layui.form.on('submit(demo1)',data=>{
			 /*  console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
			  console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
			  console.log(data.field)  *///当前容器的全部表单字段，名值对形式：{name: value}
			  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
			});
	 },
	})
</script>
</body>
</html>